<?php
class findmember_chk
{

    public function __construct ()
    {
        $this->db = new DB();
    }

    public function search_chk ($account)
    {
        global $curruser;
        $qry = $this->db->query("SELECT `id`,`account`,`prev_id`,`acl`,`name` FROM `k_user` WHERE `account`='" . $account . "' LIMIT 1");
        $rlt = mysql_fetch_array($qry);
        if (isset($rlt['acl']))
        {
            switch ($rlt['acl'])
            {
                case 4 :
                    if ($rlt['prev_id'] == $curruser['id'])
                    {
                        return true;
                    }
                    return false;
                case 3 :
                    $qry4 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `acl`=4 and `id`='" . $rlt['prev_id'] . "' LIMIT 1");
                    $rlt4 = mysql_fetch_array($qry4);
                    if (isset($rlt4))
                    {
                        $qry5 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `acl`=5 and `id`='" . $rlt4['prev_id'] . "' LIMIT 1");
                        $rlt5 = mysql_fetch_array($qry5);
                        if (isset($rlt5))
                        {
                            if ($rlt5['id'] == $curruser['id'])
                            {
                                return true;
                            }
                            return false;
                        }
                        return false;
                    }
                    return false;
                case 2 :
                    $qry3 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt['prev_id'] . "' LIMIT 1");
                    $rlt3 = mysql_fetch_array($qry3);
                    if (isset($rlt3))
                    {
                        $qry4 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt3['prev_id'] . "' LIMIT 1");
                        $rlt4 = mysql_fetch_array($qry4);
                        if (isset($rlt4))
                        {
                            $qry5 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt4['prev_id'] . "' LIMIT 1");
                            $rlt5 = mysql_fetch_array($qry5);
                            if (isset($rlt5))
                            {
                                if ($rlt5['id'] == $curruser['id'])
                                {
                                    return true;
                                }
                                return false;
                            }
                            return false;
                        }
                        return false;
                    }
                    return false;
                case 1 :
                    $qry2 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt['prev_id'] . "' LIMIT 1");
                    $rlt2 = mysql_fetch_array($qry2);
                    if (isset($rlt2))
                    {
                        $qry3 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt2['prev_id'] . "' LIMIT 1");
                        $rlt3 = mysql_fetch_array($qry3);
                        if (isset($rlt3))
                        {
                            $qry4 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt3['prev_id'] . "' LIMIT 1");
                            $rlt4 = mysql_fetch_array($qry4);
                            if (isset($rlt4))
                            {
                                $qry5 = $this->db->query("SELECT `id`,`prev_id`,`acl` FROM `k_user` WHERE `id`='" . $rlt4['prev_id'] . "' LIMIT 1");
                                $rlt5 = mysql_fetch_array($qry5);
                                if (isset($rlt5))
                                {
                                    if ($rlt5['id'] == $curruser['id'])
                                    {
                                        return true;
                                    }
                                    return false;
                                }
                                return false;
                            }
                            return false;
                        }
                        return false;
                    }
                    return false;
                default :
                    return false;
            }
        }
    }

}

?>